﻿// <copyright file="AxisAngle.cs" company="Community Combat Simulator">
//    Community Combat Simulator: a free combat flight simulator.
//    Copyright (C) 2008 Aaron Schinkowitch
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see http://www.gnu.org/licenses/.
// </copyright>
namespace CCSim.Vecmath
{
    using System;

    /// <summary>
    /// A rotation about an arbitrary axis.
    /// </summary>
    public class AxisAngle
    {
        /// <summary>
        /// The rotation angle in radians.
        /// </summary>
        private double angle;
        
        /// <summary>
        /// The axis of rotation.
        /// </summary>
        private Vector axis;
        
        /// <summary>
        /// Initializes a new instance of the AxisAngle class.
        /// </summary>
        /// <param name="angle">The rotation angle in radians.</param>
        /// <param name="axis">The axis of rotation. Must be normalized.</param>
        public AxisAngle(double angle, Vector axis)
        {
            this.Angle = angle;
            this.Axis = axis;
        }
        
        /// <summary>
        /// Gets or sets the angle of rotation in radians.
        /// </summary>
        internal double Angle 
        {
            get { return this.angle; }
            set { this.angle = value; }
        }
        
        /// <summary>
        /// Gets or sets the axis of rotation.
        /// </summary>
        internal Vector Axis
        {
            get 
            {
               return this.axis; 
            }
            
            set 
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value", "Axis cannot be null");
                }
                
                if (!value.IsNormalized())
                {
                    throw new ArgumentOutOfRangeException(
                        "value", "Axis must be normalized: " + value);
                }

                this.axis = value; 
            }
        }        
    }
}
